package com.itheima.datastructure.binarysearchtree;

/**
 * @author tantao
 * @version 1.0
 * @description: 二叉搜索树
 * @date 2025/9/25 14:56
 */
public class BSTTree11 {

    static class BSTNode {
        int key;
        Object value;

        BSTNode left;
        BSTNode right;

        public BSTNode(int key) {
            this.key = key;
        }

        public BSTNode(int key, Object value, BSTNode left, BSTNode right) {
            this.key = key;
            this.value = value;
            this.left = left;
            this.right = right;
        }

        public BSTNode(int key, Object value) {
            this.key = key;
            this.value = value;
        }
    }


    // 根节点
    BSTNode root;


    /**
     * 查找
     *
     * @param key
     * @return
     */
//    public Object get(int key) {
//        return doGet(root, key);
//    }

    private Object doGet(BSTNode node, int key) {
        if (node == null) {
            return null;
        }
        if (key < node.key) {
            return doGet(node.left, key); //向左子树找
        } else if (node.key < key) {
            return doGet(node.right, key); //向右子树找
        } else {
            return node.value; //找到
        }
    }

    /**
     * 查找
     *
     * @param key
     * @return
     */
    public Object get(int key) {
        BSTNode node = root;
        while (node != null) {
            if (key < node.key) { //向左子树找
                node = node.left;
            } else if (node.key < key) { //向右子树找
                node = node.right;
            } else {
                return node.value; //找到
            }
        }
        return null;
    }


    public Object min() {

        return null;
    }

    public Object max() {

        return null;
    }

    public void put(int key, Object value) {

    }

    public Object successor(int key) {

        return null;
    }

    public Object predecessor(int key) {

        return null;
    }

    public Object delete(int key) {

        return null;
    }
}
